package gravity;
import javax.vecmath.*;


public class MassiveBody {
        protected Point2d position;
        protected Vector2d vel;
        protected Vector2d acc;
        protected Vector2d force;
        protected double mass;
        
        public MassiveBody(){
                position = new Point2d();
                vel = new Vector2d();
                acc = new Vector2d();
                force = new Vector2d();
                mass = 1;
        }
        public MassiveBody(double m, Point2d p, Vector2d v){
                position = p;
                vel= v;
                acc = new Vector2d();
                force = new Vector2d();
                if (m != 0)
                        mass = m;
                else
                        mass = 1;
        }
        public void addVel(Vector2d v){
                vel.add(v);
        }
        public void addAcc(Vector2d a){
                acc.add(a);
        }
        public void addForce(Vector2d f){
                force.add(f);
        }
        
        public void updatePosition(double interval){
                acc.scale(1/mass,force);
                vel.add(acc);
                force.set(0,0);
                position.scaleAdd(interval,vel,position);
        }
        public void setPosition(Point2d p){
                position.set(p);
        }
        public void setPosition(double x, double y){
                position.set(x,y);
        }
        public void setVel(Vector2d v){
                vel.set(v);
        }
        public void setVel(double x, double y){
                vel.set(x,y);
        }
        public Point2d getPosition(){
                return position;
        }
        public double getX(){
                return position.x;
        }
        public double getY(){
                return position.y;
        }
        
}
